package com.glx.test.datafluxaispringboot.service.impl;

import com.glx.test.datafluxaispringboot.service.DeepSeekService;
import com.glx.test.datafluxaispringboot.utils.AliUtils;
import com.glx.test.datafluxaispringboot.utils.DeepseekUtils;
import com.glx.test.datafluxaispringboot.utils.JsonUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.io.IOException;

import static com.glx.test.datafluxaispringboot.constant.MessageEnum.SUMMARY_INFORMATION;
import static com.glx.test.datafluxaispringboot.constant.MessageEnum.TRANSLATE_INFORMATION;

@Service
public class DeepSeekServiceImpl implements DeepSeekService {

    @Autowired
    private AliUtils aliUtils;
    @Autowired
    private DeepseekUtils deepseekUtils;

    @Override
    public String translateAndSummary(String text, String type, String model) throws IOException {
        String information = getInformationByType(type);
        String jsonBody = buildJsonBody(text, information, model);
        String result = send(model, jsonBody);
        return result != null ? result : "[翻译失败]";
    }

    private String send(String model, String jsonBody) throws IOException {
        return "ali".equals(model) ? aliUtils.sendRequest(jsonBody) : deepseekUtils.sendRequest(jsonBody);
    }

    private String buildJsonBody(String text, String information, String model) throws IOException {
        return "ali".equals(model) ? JsonUtils.aliBuildJsonBody2(text, information) : JsonUtils.dsBuildJsonBody(text, information);
    }

    private String getInformationByType(String type) {
        return "翻译".equals(type) ? TRANSLATE_INFORMATION.getDesc() : SUMMARY_INFORMATION.getDesc();
    }
}
